package api

import (
	"easyShop/core/config"
	"easyShop/core/database/mysql"
	"easyShop/model"
	"github.com/gin-gonic/gin"
)

type BannerController struct {
}

func (p BannerController) GetBannerList(c *gin.Context) {
	var bannerList []model.Banner
	con := mysql.GetConnect()
	con.Select("id, image_url").Where("status = 1").Where("deleted_time is null").Find(&bannerList)
	if len(bannerList) > 0 {
		appHost := config.GetConfig("app_host").(string)
		for i := 0; i < len(bannerList); i++ {
			bannerList[i].ImageUrl = appHost + bannerList[i].ImageUrl
		}
	}
	c.JSON(200, gin.H{
		"code":    200,
		"message": "success",
		"data":    bannerList,
	})
}
